package com.yidu.erp.action.BeyondStaff;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
import com.yidu.erp.hujie.service.ModelService;
import com.yidu.erp.model.McModel;
import com.yidu.erp.model.McRoleModel;
import com.yidu.erp.model.McStaff;
import com.yidu.erp.pengzhen.service.McStaffService;
*/

/**
 * 主界面
 * @author wws
 * @date  2017年10月30日
 */

/**
@Controller
@RequestMapping("/hj")
public class IndexController {
	@Resource(name="modelService")
	private ModelService modelService;
	@Resource(name="mcStaffService")
	private McStaffService mcStaffService;
	
	
	
	
	@RequestMapping("/index")
	public String index(McStaff staff){
		McStaff staf=mcStaffService.selectStaff(staff.getStaffName());
		return "index";
	}
	
	@RequestMapping("/indexthere")
	public String indexthere(){

		return "login";
	}
	@RequestMapping("/indextwo")
	public String indexone(McStaff staff,Map<String, Object>map,HttpSession session){

		System.out.println("DDDDDDDDDDDDDD"+staff.getStaffName());
		if(staff.getStaffName()!=""){
			String modelName="";
			List<McModel> list=new ArrayList<McModel>();
			McStaff staf=mcStaffService.selectStaff(staff.getStaffName());

			session.setAttribute("staff", staf);
			String staffId=modelService.selectStaffId(staff.getStaffName());
			//得到相应角色的id
			String roleId=modelService.selectRoleId(staffId);
			String roleName=modelService.selectRoleName(roleId);

			if(roleId.indexOf(",")!=-1){
				String[] radom=roleId.split(",");
				for(int i=0;i<radom.length;i++){
					//得到模块的id
					String name1=modelService.selectModelId(radom[i]);
					//判断如果是否只有一个id
					if(name1.indexOf(",")!=-1){
						//得到模块id的数组
						String[] radom1=name1.split(",");	
						for(int j=0;j<radom1.length;j++){
							//得到模块名
							String name2=modelService.selectModelName(radom1[j]);
							modelName=name2+","+modelName;
						}

					}else{

						String name2=modelService.selectModelName(name1);
						modelName=name2+","+modelName;
					}
				}
				String[] names = modelName.split(",");
				StringBuffer new_name = new StringBuffer("");
				for(int i=0;i<names.length;i++){ 
					if(new_name.indexOf(names[i])>-1){
						continue ;
					}else{
						new_name.append(names[i]+",");
					}
				}
				String[] nameone=new_name.toString().split(",");
				for(int i=0;i<nameone.length;i++){
					McModel model=new McModel();
					String id=modelService.selectModelIdone(nameone[i]);
					List<McModel> listone=modelService.selectSonModel(id);
					System.out.println("这个集合有多大"+listone.size());
					for (Iterator iterator = listone.iterator(); iterator.hasNext();) {

						McModel mcModel = (McModel) iterator.next();
						System.out.println("这个集合有多大SSSSSSSSSS"+mcModel.getModelName());
						mcModel.setModelSumId(id);
						mcModel.setModelName(mcModel.getModelName());

						list.add(mcModel);
					}
					model.setModelId(id);
					model.setModelName(nameone[i]);
					list.add(model);
				}
			}else{
				String name1=modelService.selectModelId(roleId);

				if(name1.indexOf(",")!=-1){
					//得到模块id的数组
					String[] radom1=name1.split(",");	
					for(int j=0;j<radom1.length;j++){
						//得到模块名
						String name2=modelService.selectModelName(radom1[j]);
						modelName=name2+","+modelName;
					}
				}else{
					String name2=modelService.selectModelName(name1);
					modelName=name2+","+modelName;
				}

				String[] names = modelName.split(",");
				StringBuffer new_name = new StringBuffer("");
				for(int i=0;i<names.length;i++){ 
					if(new_name.indexOf(names[i])>-1){
						continue ;
					}else{
						new_name.append(names[i]+",");
					}
				}
				String[] nameone=new_name.toString().split(",");
				//去掉重复的
				for(int i=0;i<nameone.length;i++){
					McModel model=new McModel();
					String id=modelService.selectModelIdone(nameone[i]);
					List<McModel> listone=modelService.selectSonModel(id);
					System.out.println("这个集合有多大"+listone.size());
					for (Iterator iterator = listone.iterator(); iterator.hasNext();) {

						McModel mcModel = (McModel) iterator.next();
						mcModel.setModelSumId(id);
						mcModel.setModelName(mcModel.getModelName());

						list.add(mcModel);
					}
					model.setModelId(id);
					model.setModelName(nameone[i]);
					list.add(model);
				}

			}		
			Map<String,List> mapModel = new HashMap<String, List>();
			for (Iterator iterator = list.iterator(); iterator.hasNext();) {
				McModel m = (McModel) iterator.next();

				if(m.getModelSumId()==null ||"".equals(m.getModelSumId())){
					//list12.add(m.getModelName());
					List<McModel> list1=modelService.selectSonModel(m.getModelId());
					mapModel.put(m.getModelName(),list1);
				}


			}
			map.put("map", mapModel);
			map.put("role", roleName);
			map.put("name", staf.getStaffName());
			return "index";
		}else{

			return "login";
		}
	}

}

*/
